<template>
    <div class="wrapper">
        <!-- 方便管理和设置样式外面套一个div -->
        <swiper :options="swiperOption" v-if="showSwiper">
            <swiper-slide v-for="item of list" :key="item.id">
                <img class="swiper-img" :src="item.imgUrl">
            </swiper-slide>

            <div class="swiper-pagination" slot="pagination"></div>
        </swiper>
    </div>
</template>

<script>
export default {
    name: 'HomeSwiper',
    props: {
        list: Array
    },
    data() {
        return {
            swiperOption: {
                pagination: ".swiper-pagination",/* 在页面上显示轮播图 */
                loop: true/* 实现轮播图可以左右循环 */
                // autoplay: true
            }
        }
    },
    computed: {
        showSwiper (){
            return this.list.length
        }
    }

}
</script>

<style lang="stylus" scoped>
/* 将这个子组件从wrapper中穿透出来才能设置样式，
因为style使用了scoped设置的样式只能在本组件中才有效*/
.wrapper >>> .swiper-pagination-bullet-active
    background:#fff
.wrapper/* 防止加载页面图片还没有加载出来，字体抖动的现象 */
    overflow:hidden
    width:100%
    height:0
    padding-bottom:31.25%
    .swiper-img
        width:100%
</style>